package com.coldwindblows.blog.utils.backup.db;

import java.util.Date;

public class Row {

	private Object[] data;
	private DataTable dataTable;

	public Row(DataTable dataTabel, Object[] data) {
		this.dataTable = dataTabel;
		this.data = data;
	}

	public Object get(String columnLabel) {
		return get(dataTable.getColumns().indexByLabel(columnLabel));
	}

	public Object get(int index) {
		return data[index];
	}

	public String getString(int index) {
		return String.valueOf(get(index));
	}

	public String getString(String label) {
		return String.valueOf(get(label));
	}

	public Integer getInteger(String label) {
		return (Integer) (get(label));
	}

	public Date getDate(int index) {
		return (Date) get(index);
	}

	@Override
	public String toString() {
		if (data == null || data.length == 0) {
			return "{}";
		}
		String s = "{" + String.valueOf(data[0]);
		for (int i = 1; i < data.length; i++) {
			s += ", " + String.valueOf(data[i]);
		}
		s += "}";
		return s;
	}
}
